<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title>快乐打工网后台管理系统</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <link href="${pageContext.request.contextPath}/assets/css/bs3/dpl.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/assets/css/bui-min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/assets/css/page-min.css" rel="stylesheet" type="text/css" />   <!-- 下面的样式，仅是为了显示代码，而不应该在项目中使用-->
   <link href="${pageContext.request.contextPath}/assets/css/prettify.css" rel="stylesheet" type="text/css" />
   <style type="text/css">
    code {
      padding: 0px 4px;
      background-color: #f7f7f9;
      border: 0px solid #e1e1e8;
    }
   </style>
 </head>
 <body background="${pageContext.request.contextPath}/images/bg5.jpg">
  
  <div class="container">
    <div class="row">
       <div class="span21 offset3 control-row-auto">
          <div id="grid"></div>
       </div>
    </div>
    <div id="content" class="hide">
      <form id="J_Form" class="form-horizontal" action="${pageContext.request.contextPath}/companyWeb/addCompanySearchTypeWeb.do"  method="post">
        <div class="row">
          <div class="control-group span9">
            <label class="control-label"><s>*</s>公司搜索类型：</label>
            <div class="controls">
              <input name="searchtype" type="text" data-rules="{required:true}" class="input-normal control-text">
            </div>
          </div>
        </div>
        <div class="row">
          <input name="id"  readonly="readonly" type="hidden"  class="input-normal control-text">
        </div>
        <div class="row">
        <div class="form-actions offset3">
          <button type="submit" class="button button-primary">保存</button>
        </div>
      </div>
      </form>
    </div>
  </div>
  <script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/jquery-1.8.1.min.js"></script>
  <script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/bui.js"></script>

  <script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/config-min.js"></script>
  <script type="text/javascript">
    BUI.use('common/page');
  </script>
  <!-- 仅仅为了显示代码使用，不要在项目中引入使用-->
  <script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/prettify.js"></script>
  <script type="text/javascript">
    $(function () {
      prettyPrint();
    });
  </script> 
<script type="text/javascript">
  BUI.use(['bui/grid','bui/data','bui/form'],function (Grid,Data,Form) {

    var columns = [{title : 'id',dataIndex :'id',width:10,visible:false},
                   {title : '公司搜索类型',dataIndex :'searchtype',width:80},
                   {title : '备注',dataIndex :'remark',width:60,visible:false},
                   {title : '操作',renderer : function(){
		               return '<span class="grid-command btn-del" title="删除">删除</span>';},
		           width:50}
          ],
      //默认的数据
      data = ${companySearchType},
      store = new Data.Store({
        data:data,
        pageSize:15
      }), 
      editing = new Grid.Plugins.DialogEditing({
        contentId : 'content',
        triggerCls : 'btn-edit',
        eidtor : {
          focusable : false,
          triggerSelected:true
        }
      }),
      grid = new Grid.Grid({
        render : '#grid',
        columns : columns,
        width : 600,
        loadMask:true,//加载数据时显示屏蔽层
        forceFit : true,//标签元素宽度自适应
        store : store,
        plugins : [Grid.Plugins.CheckSelection,editing],
        tbar:{
           items : [{
                     btnCls : 'button button-small',
                     text : '<i class="icon-plus"></i>添加搜索类型',
                     listeners : {
                       'click' : addFunction
                     }
                      },{
	               btnCls : 'button button-small',
	               text : '<i class="icon-remove"></i> 批量删除',
	               listeners : {
	                 'click' : delFunction
	               }
                 }] 
        },
        bbar:{
        	pagingBar:true
        }

      });
    grid.render();

    function addFunction(){
      var newData = {school :'请输入'};
      editing.add(newData); //添加记录后，直接编辑 
    }
    function delFunction(){
        var selections = grid.getSelection();
        //store.remove(selections);
        delItems(selections);
      }
    function delItems(items){
          var ids = [];
          BUI.each(items,function(item){
            ids.push(item.id);
          });
          var ids1= BUI.JSON.stringify(ids);
          if(ids.length){
            BUI.Message.Confirm('确认要删除选中的记录么？',function(){
              $.ajax({
                url : '${pageContext.request.contextPath}/companyWeb/deleteCompanySearchWeb.do',
                dataType : 'json',
                data : {ids:ids1},
                success : function(data){
                  if(data=="1"){ //删除成功
                  	BUI.Message.Alert('删除成功！');
                  	window.location.href='${pageContext.request.contextPath}/companyWeb/companySearchTypeListWeb.do';
                  }else{ //删除失败
                    BUI.Message.Alert('删除失败！');
                  }
                }
            });
            },'question');
          }
        }
      //监听事件，删除一条记录
      grid.on('cellclick',function(ev){
        var sender = $(ev.domTarget); //点击的Dom
        if(sender.hasClass('btn-del')){
          var record = ev.record;
          delItems([record]);
        }
      });
    });
</script>

<body>
</html> 